﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Test;
using Test.Expressions;
using System.Linq.Expressions;

namespace Test
{
	public class DbQueryTSQLFormatter : TSQLTranslator
	{
		ColumnExpression[] columns;
		string innerTSQL;
		string ownerAlias;
		public DbQueryTSQLFormatter(IEnumerable<ColumnExpression> columns, string innerTSQL)
		:base(){
			this.columns = columns.ToArray();
			this.innerTSQL = innerTSQL;
			this.ownerAlias = this.columns[0].OwnerAlias ?? "T";
		}

		public override string  Translate() { 	
			this.Write("SELECT ");
			this.WriteColumns(this.columns);
			this.WriteLine();
			this.Write("FROM ");
			this.PushIndent("\t");
			this.WriteLine("(");
			this.WriteLine(this.innerTSQL);
			this.PopIndent();
			this.WriteLine();
			this.Write(") [{0}]", this.ownerAlias);
			return this.sb.ToString();
		}
		
	
	}
}
